package com.duobaoyu.dby.supply.biz.client.boundary.message;

import com.duobaoyu.dby.channel.adapter.enums.BizMessageTypeEnum;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.pojo.MessagePayload;
import com.duobaoyu.dby.supply.core.framework.strategy.AbstractStrategy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.Set;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName AbstractMessageTypeHandlerStrategy
 * @Description 消息类型处理器
 * @createTime 16:58:00 2023/09/27
 */
public abstract class AbstractMessageTypeHandlerStrategy extends AbstractStrategy<MessagePayload.ChannelMessage, Void> {

	/**
	 * @return
	 * @see BizMessageTypeEnum
	 */
	protected Set<Integer> bizMessageTypes() {
		return Collections.emptySet();
	}

	@Override
	public final boolean support(Object... args) {
		if (ObjectUtils.isNotEmpty(args) && CollectionUtils.isNotEmpty(this.bizMessageTypes())) {
			return Arrays.stream(args).anyMatch(item -> this.bizMessageTypes().contains((Integer) item));
		}
		return false;
	}
}
